﻿#define _CRT_SECURE_NO_WARNINGS 1


#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>

using namespace std;

class Solution
{
public:
    int coinChange(vector<int>& coins, int amount)
    {
        // 1. 创建 dp 表
        // 2. 初始化
        // 3. 填表
        // 4. 返回值
        const int INF = 0x3f3f3f3f;
        int n = coins.size();
        vector<int> dp(amount + 1, INF);
        dp[0] = 0;
        for (int i = 1; i <= n; i++)
            for (int j = coins[i - 1]; j <= amount; j++)
                dp[j] = min(dp[j], dp[j - coins[i - 1]] + 1);
        return dp[amount] >= INF ? -1 : dp[amount];
    }
};

int main()
{
    vector<int> coins = { 1, 2, 5 };
    int amount = 11;

    cout << Solution().coinChange(coins, amount) << endl;

    return 0;
}


